<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
    <!-- 引入 layui.css -->    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
    <!-- 引入 layui.js -->    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
</head>
<style>
    .window{
        height: 500px;
        width:400px;
        margin:0 auto;
    }
</style>
<body>
<center>
<div>
    <div class="window">
        <a href="/notice">公告</a>
        <form class="layui-form" action="">
            <div class="layui-form-item" style="margin-top:200px">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="title" lay-verify="title" id="username" autocomplete="off" placeholder="请输入用户名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="title" id="password" autocomplete="off" placeholder="请输入密码" class="layui-input">
            </div>
        </div>
            <div class="layui-btn-container" style="text-align: center">
            <button type="button" id="login" class="layui-btn layui-btn-normal">登录</button>
        </div>

        </form>
    </div>
</div>


</center>
</body>

<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
    $(function(){
        $("#login").on("click",function () {
            var username = $("#username").val();
            var password = $("#password").val();
            var user = {};
            user.username = username;
            user.password = password;
            $.ajax({
                url:"/login",
                type:"post",
                data:user,
                success:function (rs) {
                    if(rs == "登录成功"){
                        alert("欢迎用户"+username);
                        window.location.href="/home";
                        console.log(rs);
                    }else {
                        alert("登录失败！")
                        window.location.href="/login_page";
                        console.log(rs);
                    }

                }
            })
        })
    })
</script>
</html>
